export const new_session = "new_session";
export const default_scene = {
  // id: "",
  // name: "",
  // type: "",
};

// 通用对话
export const default_chat = "default";
// 知识库
export const knowledgeBase = "knowledgeBase";
export const localKbName = "knowledgeBase_local";
// 数据分析
export const dataAnalysis = "chatBI";
// chatTPT
export const chatTPT = "chatTPT";
// 深度思考
export const deepThink = "deepThink";
// 离线数据
export const offlineData = "offlineData";
// 工艺参数预测
export const processParameterPrediction = "processParameterPrediction";
// 设备异常检测
export const deviceAnomalyDetection = "sbyc";
// 过程数据分析
export const processDataAnalysis = "processDataAnalysis";
// PID参数整定
export const pid = "pid";
// 质量预测
export const qualityPrediction = "qualityPrediction";
// 操作优化
export const operationOptimization = "operationOptimization";
// 知识问答与培训
export const questionAnswerTraining = "questionAnswerTraining";

export const quickScene = ["chatTPT", "chatBI", knowledgeBase];
// 知识库 数据集
export const h5_quickScene = [knowledgeBase, dataAnalysis];
// export const h5_quickScene = ["chatTPT", "chatBI", knowledgeBase];
// 知识库: 会展示 [使用, 配置]
export const knowledgeBase_Scene = [knowledgeBase];

export const isIOS = () => {
  return /iPhone|iPad|iPod/i.test(navigator.userAgent);
};

export function parseString(str: string) {
  try {
    const repalceStr = str.replaceAll("'", '"');
    const resStr = JSON.parse(repalceStr);
    return resStr;
  } catch (err) {
    return false;
  }
}

/**
 * 复制文本
 * @param {string} text
 * @returns {Promise<void>}
 */
export function copyText(text: string): Promise<void> {
  if (navigator && navigator.clipboard) {
    return navigator.clipboard.writeText(text);
  } else {
    return new Promise((reslove, reject) => {
      try {
        const textarea = document.createElement("textarea");
        textarea.value = text;
        document.body.appendChild(textarea);
        textarea.select();
        document.execCommand("copy");
        document.body.removeChild(textarea);
        reslove();
      } catch (err) {
        reject(err);
      }
    });
  }
}

//生成唯一不重复ID
export const generateUuid = () => {
  // return Number(
  //   Math.random().toString().substr(3, length) + Date.now()
  // ).toString(36);
  let s: any[] = [];
  let hexDigits = "0123456789qwerty";
  for (let i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";
  let uuid = s.join("").replace("-", "");

  return uuid;
};
